"use strict";
cc._RF.push(module, 'b73a9Bj9QlOYawZaRDi0K9e', 'StartScene');
// Script/StartScene.ts

"use strict";
/**
 * 开始界面
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var AudioManager_1 = require("./SdkTools/AudioManager");
var Define_1 = require("./SdkTools/Define");
var gameCheckLogin_1 = require("./SdkTools/gameCheckLogin");
var gamePrefabMgr_1 = require("./SdkTools/gamePrefabMgr");
var gameShareAdsVideo_1 = require("./SdkTools/gameShareAdsVideo");
var gameStorage_1 = require("./SdkTools/gameStorage");
var PlayData_1 = require("./SdkTools/PlayData");
var storage_1 = require("./SdkTools/storage");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var StartScene = /** @class */ (function (_super) {
    __extends(StartScene, _super);
    function StartScene() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.top = null;
        _this.soundbtn = null;
        _this.subContextNode = null;
        return _this;
        // update (dt) {}
    }
    StartScene.prototype.onLoad = function () {
        AudioManager_1.default.setSoundEvent();
        if (storage_1.default.Instance.isfirstlogin == !0) {
            storage_1.default.Instance.getUserInfo();
            this.setOffTimeTiLi();
        }
        //console.log('打印终端信息', tt.getSystemInfoSync())
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            // cc.find('Canvas/bg/left/rank').active = !1
            //@ts-ignore
            // const sysinfo = tt.getSystemInfoSync()
            // const sdkversion = sysinfo.SDKVersion
            // let appname = sysinfo.appName
            // let appVersion = sysinfo.version
            // if (Utils.compareVersion(sdkversion, '2.70.0') >= 0
            //     && (appname == 'Douyin' || appname == 'douyin_lite')
            //     && Utils.compareVersion(appVersion, '23.2.0') >= 0) {
            //         cc.find('bg/right/rank', this.node).active = !0
            // }else{
            //     cc.find('bg/left/rank', this.node).active = !1
            // }
        }
        else if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            //@ts-ignore
            // let env = window.wx
            // if (env) {
            //     console.log('Message posted');
            //     env.getOpenDataContext().postMessage({
            //         value: 'MESSAGE FROM MAIN PROJECT',
            //     });
            // }
            //cc.find('bg/left/rank', this.node).active = !1
        }
        else {
            // cc.find('bg/left/rank', this.node).active = !1
        }
        //放最后
        storage_1.default.Instance.isfirstlogin = !1;
    };
    StartScene.prototype.start = function () {
        if (gameStorage_1.default.getMusic() == 1) {
            cc.find('on', this.soundbtn).active = !1;
            cc.find('off', this.soundbtn).active = !0;
        }
        else {
            cc.find('on', this.soundbtn).active = !0;
            cc.find('off', this.soundbtn).active = !1;
        }
        cc.director.emit('main_bg');
        gameShareAdsVideo_1.default.Instance.showCustomAd(Define_1.CustomAdType.Shu);
    };
    /**
     * 设置离线体力
     */
    StartScene.prototype.setOffTimeTiLi = function () {
        if (gameStorage_1.default.getoffLineTime() > 0) {
            var nowtime = Number(new Date().getTime());
            var offtime = gameStorage_1.default.getoffLineTime();
            var _chatime = Math.floor((nowtime - offtime) / 1000);
            var addtili = Math.floor(_chatime / Define_1.default.eneryTime);
            if (storage_1.default.Instance.getEnergy() < Define_1.default.maxEnery) {
                if ((addtili + storage_1.default.Instance.getEnergy()) >= Define_1.default.maxEnery) {
                    storage_1.default.Instance.setEnergy(Define_1.default.maxEnery);
                    cc.director.emit('addengry');
                }
                else {
                    storage_1.default.Instance.setEnergy(addtili + storage_1.default.Instance.getEnergy());
                    cc.director.emit('addengry');
                }
            }
        }
        gameStorage_1.default.setoffLineTime();
    };
    /**
     * 开始按钮
     */
    StartScene.prototype.startBtnClick = function (t, e) {
        if (e == 'huaijiu') {
            PlayData_1.default.Instance.gameType = PlayData_1.GameType.finddifference_zhaobutong;
        }
        gameShareAdsVideo_1.default.Instance.hideCustomAd(Define_1.CustomAdType.Shu);
        var newnode = cc.instantiate(gamePrefabMgr_1.default.Instance.uiPre[gamePrefabMgr_1.uiPreName.checkoutPanel]);
        newnode.parent = cc.director.getScene();
    };
    /**
     * 音效开关
     */
    StartScene.prototype.sountBtn = function () {
        if (gameStorage_1.default.getMusic() == 1) {
            gameStorage_1.default.setMusic(0);
            cc.director.emit('main_bg');
            cc.find('on', this.soundbtn).active = !0;
            cc.find('off', this.soundbtn).active = !1;
            gameStorage_1.default.setSound(0);
        }
        else {
            gameStorage_1.default.setMusic(1);
            cc.audioEngine.stopMusic();
            cc.find('on', this.soundbtn).active = !1;
            cc.find('off', this.soundbtn).active = !0;
            gameStorage_1.default.setSound(1);
        }
    };
    /**
     * 排行榜按钮点击
     */
    StartScene.prototype.rankClick = function () {
        //gameShareAdsVideo.Instance.getImRankList_Num()
        //this.subContextNode.active = !0
        this.subContextNode.x = 0;
        var self = this;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            if (gameCheckLogin_1.default.gameCode) {
                console.log('开启排行');
                gameCheckLogin_1.default.wx_getUserInfo(function () {
                    self.openPaiHangPanel();
                });
            }
            else {
                //@ts-ignore
                wx.showModal({
                    title: "提示！",
                    content: "请先登录？",
                    success: function (res) {
                        if (res.confirm) {
                            gameCheckLogin_1.default.gameLogin(true);
                        }
                        else if (res.cancel) {
                            //console.log("cancel, cold");
                        }
                        else {
                            // what happend?
                        }
                    },
                    fail: function (res) {
                        //console.log(`showModal调用失败`);
                    },
                });
            }
        }
    };
    /**
     * 打开排行榜界面
     */
    StartScene.prototype.openPaiHangPanel = function () {
        gameShareAdsVideo_1.default.Instance.chaPingAds_Show();
        //gameShareAdsVideo.Instance.bannerAds_Hide()
        // this.rankpanel.active = !0
        // this.rankpanel.x = 0
        // console.log('打印数据域节点=', cc.find('kuang/sub', this.rankpanel))
        // let sub = cc.find('kuang/sub', this.rankpanel).getComponent(cc.SubContextView)
        // sub.enabled = !0
        //sub.updateSubContextViewport()
        this.subContextNode.active = !1;
        //@ts-ignore
        // let env = window.wx
        // if (env) {
        //     console.log('Message posted');
        //     env.getOpenDataContext().postMessage({
        //         value: 'MESSAGE FROM MAIN PROJECT',
        //     });
        // }
        //@ts-ignore
        var openDataContext = wx.getOpenDataContext();
        console.log('向子域发消息');
        openDataContext.postMessage({
            event: 'getRank',
            name: PlayData_1.default.Instance.userInfo.name,
            icon: PlayData_1.default.Instance.userInfo.icon
        });
    };
    StartScene.prototype.closeRankPanel = function () {
        this.subContextNode.active = !1;
    };
    /**
     * 排行榜邀请好友
     */
    StartScene.prototype.shareGame = function () {
        gameShareAdsVideo_1.default.Instance.recording_Video_Share(function () { }, function () { });
    };
    __decorate([
        property(cc.Node)
    ], StartScene.prototype, "top", void 0);
    __decorate([
        property(cc.Node)
    ], StartScene.prototype, "soundbtn", void 0);
    __decorate([
        property(cc.Node)
    ], StartScene.prototype, "subContextNode", void 0);
    StartScene = __decorate([
        ccclass
    ], StartScene);
    return StartScene;
}(cc.Component));
exports.default = StartScene;

cc._RF.pop();